package com.central.scheduler.dao.mapper;

import com.central.db.mapper.SuperMapper;
import com.central.scheduler.dao.entity.CommandCount;
import com.central.scheduler.dao.model.ErrorCommand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * @author Tindy
 * @date 2021/11/5
 * @describe
 * error command mapper interface
 */
@Mapper
public interface ErrorCommandMapper extends SuperMapper<ErrorCommand> {

    @Insert("INSERT INTO sch_error_command (id,command_type, process_definition_code, user_id,username, pro_id,pro_name, command_param, task_depend_type, failure_strategy, warning_type, warning_group_id, start_time, process_instance_priority, message, dry_run, create_time, update_time ) " +
            "VALUES ( #{c.id},#{c.commandType},#{c.processDefinitionCode},#{c.userId},#{c.username},#{c.proId},#{c.proName},#{c.commandParam}, " +
            "#{c.taskDependType},#{c.failureStrategy},#{c.warningType},#{c.warningGroupId},#{c.startTime}, " +
            "#{c.processInstancePriority},#{c.message},#{c.dryRun},#{c.createTime},#{c.updateTime})")
    @Override
    int insert(@Param("c") ErrorCommand errorCommand);

    /**
     * count command state
     * @param startTime startTime
     * @param endTime endTime
     * @param proIds proIds
     * @return CommandCount list
     */
    List<CommandCount> countCommandState(
            @Param("startTime") Date startTime,
            @Param("endTime") Date endTime,
            @Param("proIds") Long[] proIds);
}

